const notice = require('./../server/noticeServer');
let noticeServer = new notice();

function notice_server() {
    let result = {};
    this.queryAll = (req,res) => {
        console.log(req.query);
        noticeServer.queryNotice(req,rows => {
            result.code=1;
            result.data = rows;
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.add = (req,res) => {
        noticeServer.addNotice(req.body, rows => {
            if (rows){
                result.code=1;
                result.msg = '添加成功';
            } else{
                result.code=0;
                result.msg = '添加失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.del = (req,res) => {
        noticeServer.delNotice(req.body,rows => {
            if (rows){
                result.code=1;
                result.msg = '删除成功';
            } else{
                result.code=0;
                result.msg = '删除失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.modify = (req,res) => {
        noticeServer.modifyNotice(req.body,rows => {
            if (rows){
                result.code=1;
                result.msg = '修改成功';
            } else{
                result.code=0;
                result.msg = '修改失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
};
module.exports = notice_server;
